<template>
  <div>
    <div class="app-container">
      <!-- 输入表单 -->
      <el-form label-width="120px">
        <el-form-item label="借款额度">
          <el-input-number v-model="integralGrade.borrowAmount" :min="0" />
        </el-form-item>
        <el-form-item label="积分区间开始">
          <el-input-number v-model="integralGrade.integralStart" :min="0" />
        </el-form-item>
        <el-form-item label="积分区间结束">
          <el-input-number v-model="integralGrade.integralEnd" :min="0" />
        </el-form-item>
        <el-form-item>
          <el-button
            :disabled="saveBtnDisabled"
            type="primary"
            @click="saveOrUpdate()"
          >
            保存
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { saveIntegralGrade, updateIntegralGrade, getIngettegralGradeById } from '@/api/core/integral-grade'

export default {
  data() {
    return {
      // 是否禁用保存按钮
      saveBtnDisabled: false,
      integralGrade:{}
    }
  },
  created() {
    if(this.$route.params.id){
      this.getInfoById(this.$route.params.id)
    }
  },
  methods: {
    getInfoById(id) {
      getIngettegralGradeById(id).then(response => {
        this.integralGrade = response.data.record
      })
    },
    saveOrUpdate() {
      if(this.integralGrade.id){
        this.updateDate()
      } else {
        this.saveData()
      }
    },
    saveData() { 
      saveIntegralGrade(this.integralGrade).then(response => {
        this.$message({
          type: 'success',
          message: response.message
        })
        this.$router.push('/core/integral-grade/list')
      })
    },
    updateDate() {
      updateIntegralGrade(this.integralGrade).then(response => {
        this.$message({
          type: 'success',
          message: response.message
        })
        this.$router.push('/core/integral-grade/list')
      })
    }
  }
}
</script>
<style scoped>
</style>